package cn.rengy.web.framework.shiro.realm;

import org.apache.shiro.authc.credential.CredentialsMatcher;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.authz.SimpleAuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;
import org.springframework.beans.factory.annotation.Autowired;

import cn.rengy.web.framework.principal.Identity;
import cn.rengy.web.framework.sys.userrole.service.UserRoleService;

public abstract class IAuthorizingRealm extends AuthorizingRealm {
	
	public IAuthorizingRealm() {
		super();
	}
	public IAuthorizingRealm(CredentialsMatcher matcher) {
		super(null, matcher);
    }
	@Autowired
	private UserRoleService userRoleService;
	
	
	@Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        //获取当前登录输入的用户名
		Identity identity=(Identity) principalCollection.getPrimaryPrincipal();
		String user_id=identity.getUserid().toString();
    	SimpleAuthorizationInfo info=new SimpleAuthorizationInfo();
    	info.addRoles(userRoleService.getRoles(user_id));
        info.addStringPermission("sys:sql:all");
        return info;
    }
	
}
